package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.system.service.Test1Service;
import org.jeecg.modules.system.vo.DataItem;
import org.jeecg.modules.system.vo.QueryParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author scott
 * @since 2018-12-20
 */
@Slf4j
@RestController
@RequestMapping("/dashboard/test")
public class Test1Controller {

    @Autowired
    private Test1Service test1Service;

    @ApiOperation("获取列表")
    @RequestMapping(value = "/queryPage", method = RequestMethod.POST)
    public Result<Page<DataItem>> queryPage(@RequestBody QueryParams queryParams) {
        Page<DataItem> result = test1Service.queryPage(queryParams);
        return Result.ok(result);
    }

    @ApiOperation("新增或者更新")
    @RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
    public Result<Integer> saveOrUpdate(@RequestBody DataItem param) {
        int result = test1Service.saveOrUpdate(param);
        return Result.ok(result);
    }

    @ApiOperation("删除一条记录")
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.POST)
    public Result<Integer> saveOrUpdate(@PathVariable(value = "id") Integer id) {
        int result = test1Service.deleteById(id);
        return Result.ok(result);
    }

    @ApiOperation("详情")
    @RequestMapping(value = "/details/{id}", method = RequestMethod.GET)
    public Result<DataItem> details(@PathVariable(value = "id") Integer id) {
        DataItem result = test1Service.details(id);
        return Result.ok(result);
    }

}
